<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>云校园快递代取系统</title>
    <link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <script src="https://fastly.jsdelivr.net/npm/chart.js"></script>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            background-color: #f4f4f9; /* 背景颜色 */
            color: #333; /* 文字颜色 */
        }

        h1 {
            color: #007bff; /* 标题颜色 */
            margin-top: 20px;
        }

        .tab-container {
            width: 90%;
            max-width: 1200px; /* 最大宽度 */
            margin-top: 20px;
            background-color: #fff; /* 标签容器背景颜色 */
            border-radius: 8px; /* 圆角 */
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* 阴影 */
        }

        .nav-tabs {
            justify-content: center;
            background-color: #007bff; /* 标签栏背景颜色 */
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
        }

        .nav-link {
            color: #fff; /* 标签文字颜色 */
            transition: background-color 0.3s ease; /* 过渡效果 */
        }

        .nav-link.active {
            background-color: #fff; /* 激活标签背景颜色 */
            color: #007bff; /* 激活标签文字颜色 */
        }

        .tab-content {
            padding: 20px;
            border: none;
            border-bottom-left-radius: 8px;
            border-bottom-right-radius: 8px;
        }

        table {
            width: 100%;
            margin-top: 20px;
            border-collapse: collapse;
        }

        th,
        td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        th {
            background-color: #f0f0f0; /* 表头背景颜色 */
        }

    /* 按钮样式 */
    .btn {
        padding: 10px 20px;
        font-size: 16px;
        border: none;
        border-radius: 25px;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
    }

    .btn-primary {
        background-color: #007bff;
        color: #fff;
    }

    .btn-primary:hover {
        background-color: #0056b3;
        transform: translateY(-2px);
        box-shadow: 0 7px 14px rgba(50, 50, 93, 0.1), 0 3px 6px rgba(0, 0, 0, 0.08);
    }

    .btn-warning {
        background-color: #ffc107;
        color: #fff;
    }

    .btn-warning:hover {
        background-color: #d39e00;
        transform: translateY(-2px);
        box-shadow: 0 7px 14px rgba(50, 50, 93, 0.1), 0 3px 6px rgba(0, 0, 0, 0.08);
    }

    .btn-danger {
        background-color: #dc3545;
        color: #fff;
    }

    .btn-danger:hover {
        background-color: #bd2130;
        transform: translateY(-2px);
        box-shadow: 0 7px 14px rgba(50, 50, 93, 0.1), 0 3px 6px rgba(0, 0, 0, 0.08);
    }

    </style>
</head>

<body>
    <h1>云校园快递代取系统</h1>
    <div class="tab-container">
        <ul class="nav nav-tabs" id="myTab" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button"
                    role="tab" aria-controls="home" aria-selected="true">首页</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="courier-tab" data-bs-toggle="tab" data-bs-target="#courier" type="button"
                    role="tab" aria-controls="courier" aria-selected="false">快递员管理</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="student-tab" data-bs-toggle="tab" data-bs-target="#student" type="button"
                    role="tab" aria-controls="student" aria-selected="false">学生管理</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="package-tab" data-bs-toggle="tab" data-bs-target="#package" type="button"
                    role="tab" aria-controls="package" aria-selected="false">包裹管理</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="order-tab" data-bs-toggle="tab" data-bs-target="#order" type="button"
                    role="tab" aria-controls="order" aria-selected="false">订单管理</button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="feedback-tab" data-bs-toggle="tab" data-bs-target="#feedback" type="button"
                    role="tab" aria-controls="feedback" aria-selected="false">反馈管理</button>
            </li>
        </ul>
        <div class="tab-content" id="myTabContent">
            <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                <h2>首页</h2>
                <canvas id="myPieChart" width="400" height="200"></canvas>
            </div>
            <div class="tab-pane fade" id="courier" role="tabpanel" aria-labelledby="courier-tab">
                <h2>快递员管理</h2>
                <input type="text" id="courierSearch" placeholder="搜索快递员姓名" oninput="searchCouriers()">
                <button class="btn btn-primary" onclick="openAddCourierModal()">添加快递员</button>
                <table id="courierTable" class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>姓名</th>
                            <th>联系方式</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="tab-pane fade" id="student" role="tabpanel" aria-labelledby="student-tab">
                <h2>学生管理</h2>
                <input type="text" id="studentSearch" placeholder="搜索学生姓名" oninput="searchStudents()">
                <button class="btn btn-primary" onclick="openAddStudentModal()">添加学生</button>
                <table id="studentTable" class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>姓名</th>
                            <th>学号</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="tab-pane fade" id="package" role="tabpanel" aria-labelledby="package-tab">
                <h2>包裹管理</h2>
                <input type="text" id="packageSearch" placeholder="搜索包裹单号" oninput="searchPackages()">
                <button class="btn btn-primary" onclick="openAddPackageModal()">添加包裹</button>
                <table id="packageTable" class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>单号</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="tab-pane fade" id="order" role="tabpanel" aria-labelledby="order-tab">
                <h2>订单管理</h2>
                <input type="text" id="orderSearch" placeholder="搜索订单编号" oninput="searchOrders()">
                <button class="btn btn-primary" onclick="openAddOrderModal()">添加订单</button>
                <table id="orderTable" class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>订单编号</th>
                            <th>下单时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="tab-pane fade" id="feedback" role="tabpanel" aria-labelledby="feedback-tab">
                <h2>反馈管理</h2>
                <input type="text" id="feedbackSearch" placeholder="搜索反馈人姓名" oninput="searchFeedbacks()">
                <button class="btn btn-primary" onclick="openAddFeedbackModal()">添加反馈</button>
                <table id="feedbackTable" class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>反馈人</th>
                            <th>反馈内容</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- 快递员添加/编辑模态框 -->
    <div class="modal fade" id="courierModal" tabindex="-1" aria-labelledby="courierModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="courierModalLabel">添加/编辑快递员</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="courierId">
                    <label for="courierName">姓名</label>
                    <input type="text" id="courierName" class="form-control">
                    <label for="courierContact">联系方式</label>
                    <input type="text" id="courierContact" class="form-control">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="saveCourier()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 学生添加/编辑模态框 -->
    <div class="modal fade" id="studentModal" tabindex="-1" aria-labelledby="studentModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="studentModalLabel">添加/编辑学生</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="studentId">
                    <label for="studentName">姓名</label>
                    <input type="text" id="studentName" class="form-control">
                    <label for="studentNumber">学号</label>
                    <input type="text" id="studentNumber" class="form-control">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="saveStudent()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 包裹添加/编辑模态框 -->
    <div class="modal fade" id="packageModal" tabindex="-1" aria-labelledby="packageModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="packageModalLabel">添加/编辑包裹</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="packageId">
                    <label for="packageNumber">单号</label>
                    <input type="text" id="packageNumber" class="form-control">
                    <label for="packageStatus">状态</label>
                    <input type="text" id="packageStatus" class="form-control">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="savePackage()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 订单添加/编辑模态框 -->
    <div class="modal fade" id="orderModal" tabindex="-1" aria-labelledby="orderModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="orderModalLabel">添加/编辑订单</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="orderId">
                    <label for="orderNumber">订单编号</label>
                    <input type="text" id="orderNumber" class="form-control">
                    <label for="orderTime">下单时间</label>
                    <input type="text" id="orderTime" class="form-control">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="saveOrder()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 反馈添加/编辑模态框 -->
    <div class="modal fade" id="feedbackModal" tabindex="-1" aria-labelledby="feedbackModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="feedbackModalLabel">添加/编辑反馈</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="feedbackId">
                    <label for="feedbackPerson">反馈人</label>
                    <input type="text" id="feedbackPerson" class="form-control">
                    <label for="feedbackContent">反馈内容</label>
                    <input type="text" id="feedbackContent" class="form-control">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="saveFeedback()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 初始化表格和图表
        function init() {
            initCouriers();
            initStudents();
            initPackages();
            initOrders();
            initFeedbacks();
            initChart();
        }

        // 员工管理
        function initCouriers() {
            let couriers = JSON.parse(localStorage.getItem('couriers')) || [
                { id: 1, name: '快递员1', contact: '13800138001' },
                { id: 2, name: '快递员2', contact: '13800138002' },
                { id: 3, name: '快递员3', contact: '13800138003' },
                { id: 4, name: '快递员4', contact: '13800138004' },
                { id: 5, name: '快递员5', contact: '13800138005' },
                { id: 6, name: '快递员6', contact: '13800138006' },
                { id: 7, name: '快递员7', contact: '13800138007' },
                { id: 8, name: '快递员8', contact: '13800138008' },
                { id: 9, name: '快递员9', contact: '13800138009' },
                { id: 10, name: '快递员10', contact: '13800138010' }
            ];
            localStorage.setItem('couriers', JSON.stringify(couriers));
            renderCouriers(couriers);
        }

        function renderCouriers(couriers) {
            let courierTable = document.getElementById('courierTable').getElementsByTagName('tbody')[0];
            courierTable.innerHTML = '';
            couriers.forEach(courier => {
                let row = courierTable.insertRow();
                row.insertCell(0).textContent = courier.id;
                row.insertCell(1).textContent = courier.name;
                row.insertCell(2).textContent = courier.contact;
                let actionsCell = row.insertCell(3);
                actionsCell.innerHTML = `<button class="btn btn-warning" onclick="openEditCourierModal(${courier.id})">编辑</button>
                                         <button class="btn btn-danger" onclick="deleteCourier(${courier.id})">删除</button>`;
            });
        }

        function openAddCourierModal() {
            document.getElementById('courierId').value = '';
            document.getElementById('courierName').value = '';
            document.getElementById('courierContact').value = '';
            let courierModal = new bootstrap.Modal(document.getElementById('courierModal'));
            courierModal.show();
        }

        function openEditCourierModal(id) {
            let couriers = JSON.parse(localStorage.getItem('couriers'));
            let courier = couriers.find(c => c.id === id);
            document.getElementById('courierId').value = courier.id;
            document.getElementById('courierName').value = courier.name;
            document.getElementById('courierContact').value = courier.contact;
            let courierModal = new bootstrap.Modal(document.getElementById('courierModal'));
            courierModal.show();
        }

        function saveCourier() {
            let couriers = JSON.parse(localStorage.getItem('couriers'));
            let id = document.getElementById('courierId').value;
            let name = document.getElementById('courierName').value;
            let contact = document.getElementById('courierContact').value;
            if (id) {
                let index = couriers.findIndex(c => c.id === parseInt(id));
                couriers[index] = { id: parseInt(id), name, contact };
            } else {
                let newId = couriers.length > 0 ? Math.max(...couriers.map(c => c.id)) + 1 : 1;
                couriers.push({ id: newId, name, contact });
            }
            localStorage.setItem('couriers', JSON.stringify(couriers));
            renderCouriers(couriers);
            let courierModal = bootstrap.Modal.getInstance(document.getElementById('courierModal'));
            courierModal.hide();
        }

        function deleteCourier(id) {
            let couriers = JSON.parse(localStorage.getItem('couriers'));
            couriers = couriers.filter(c => c.id!== id);
            localStorage.setItem('couriers', JSON.stringify(couriers));
            renderCouriers(couriers);
        }

        function searchCouriers() {
            let searchTerm = document.getElementById('courierSearch').value.toLowerCase();
            let couriers = JSON.parse(localStorage.getItem('couriers'));
            let filteredCouriers = couriers.filter(courier => courier.name.toLowerCase().includes(searchTerm));
            renderCouriers(filteredCouriers);
        }

        // 学生管理
        function initStudents() {
            let students = JSON.parse(localStorage.getItem('students')) || [
                { id: 1, name: '学生1', number: '20240001' },
                { id: 2, name: '学生2', number: '20240002' },
                { id: 3, name: '学生3', number: '20240003' },
                { id: 4, name: '学生4', number: '20240004' },
                { id: 5, name: '学生5', number: '20240005' },
                { id: 6, name: '学生6', number: '20240006' },
                { id: 7, name: '学生7', number: '20240007' },
                { id: 8, name: '学生8', number: '20240008' },
                { id: 9, name: '学生9', number: '20240009' },
                { id: 10, name: '学生10', number: '20240010' }
            ];
            localStorage.setItem('students', JSON.stringify(students));
            renderStudents(students);
        }

        function renderStudents(students) {
            let studentTable = document.getElementById('studentTable').getElementsByTagName('tbody')[0];
            studentTable.innerHTML = '';
            students.forEach(student => {
                let row = studentTable.insertRow();
                row.insertCell(0).textContent = student.id;
                row.insertCell(1).textContent = student.name;
                row.insertCell(2).textContent = student.number;
                let actionsCell = row.insertCell(3);
                actionsCell.innerHTML = `<button class="btn btn-warning" onclick="openEditStudentModal(${student.id})">编辑</button>
                                         <button class="btn btn-danger" onclick="deleteStudent(${student.id})">删除</button>`;
            });
        }

        function openAddStudentModal() {
            document.getElementById('studentId').value = '';
            document.getElementById('studentName').value = '';
            document.getElementById('studentNumber').value = '';
            let studentModal = new bootstrap.Modal(document.getElementById('studentModal'));
            studentModal.show();
        }

        function openEditStudentModal(id) {
            let students = JSON.parse(localStorage.getItem('students'));
            let student = students.find(s => s.id === id);
            document.getElementById('studentId').value = student.id;
            document.getElementById('studentName').value = student.name;
            document.getElementById('studentNumber').value = student.number;
            let studentModal = new bootstrap.Modal(document.getElementById('studentModal'));
            studentModal.show();
        }

        function saveStudent() {
            let students = JSON.parse(localStorage.getItem('students'));
            let id = document.getElementById('studentId').value;
            let name = document.getElementById('studentName').value;
            let number = document.getElementById('studentNumber').value;
            if (id) {
                let index = students.findIndex(s => s.id === parseInt(id));
                students[index] = { id: parseInt(id), name, number };
            } else {
                let newId = students.length > 0 ? Math.max(...students.map(s => s.id)) + 1 : 1;
                students.push({ id: newId, name, number });
            }
            localStorage.setItem('students', JSON.stringify(students));
            renderStudents(students);
            let studentModal = bootstrap.Modal.getInstance(document.getElementById('studentModal'));
            studentModal.hide();
        }

        function deleteStudent(id) {
            let students = JSON.parse(localStorage.getItem('students'));
            students = students.filter(s => s.id!== id);
            localStorage.setItem('students', JSON.stringify(students));
            renderStudents(students);
        }

        function searchStudents() {
            let searchTerm = document.getElementById('studentSearch').value.toLowerCase();
            let students = JSON.parse(localStorage.getItem('students'));
            let filteredStudents = students.filter(student => student.name.toLowerCase().includes(searchTerm));
            renderStudents(filteredStudents);
        }

        // 包裹管理
        function initPackages() {
            let packages = JSON.parse(localStorage.getItem('packages')) || [
                { id: 1, number: '12345678901', status: '待取件' },
                { id: 2, number: '12345678902', status: '已取件' },
                { id: 3, number: '12345678903', status: '待取件' },
                { id: 4, number: '12345678904', status: '已取件' },
                { id: 5, number: '12345678905', status: '待取件' },
                { id: 6, number: '12345678906', status: '已取件' },
                { id: 7, number: '12345678907', status: '待取件' },
                { id: 8, number: '12345678908', status: '已取件' },
                { id: 9, number: '12345678909', status: '待取件' },
                { id: 10, number: '12345678910', status: '已取件' }
            ];
            localStorage.setItem('packages', JSON.stringify(packages));
            renderPackages(packages);
        }

        function renderPackages(packages) {
            let packageTable = document.getElementById('packageTable').getElementsByTagName('tbody')[0];
            packageTable.innerHTML = '';
            packages.forEach(package => {
                let row = packageTable.insertRow();
                row.insertCell(0).textContent = package.id;
                row.insertCell(1).textContent = package.number;
                row.insertCell(2).textContent = package.status;
                let actionsCell = row.insertCell(3);
                actionsCell.innerHTML = `<button class="btn btn-warning" onclick="openEditPackageModal(${package.id})">编辑</button>
                                         <button class="btn btn-danger" onclick="deletePackage(${package.id})">删除</button>`;
            });
        }

        function openAddPackageModal() {
            document.getElementById('packageId').value = '';
            document.getElementById('packageNumber').value = '';
            document.getElementById('packageStatus').value = '';
            let packageModal = new bootstrap.Modal(document.getElementById('packageModal'));
            packageModal.show();
        }

        function openEditPackageModal(id) {
            let packages = JSON.parse(localStorage.getItem('packages'));
            let package = packages.find(p => p.id === id);
            document.getElementById('packageId').value = package.id;
            document.getElementById('packageNumber').value = package.number;
            document.getElementById('packageStatus').value = package.status;
            let packageModal = new bootstrap.Modal(document.getElementById('packageModal'));
            packageModal.show();
        }

        function savePackage() {
            let packages = JSON.parse(localStorage.getItem('packages'));
            let id = document.getElementById('packageId').value;
            let number = document.getElementById('packageNumber').value;
            let status = document.getElementById('packageStatus').value;
            if (id) {
                let index = packages.findIndex(p => p.id === parseInt(id));
                packages[index] = { id: parseInt(id), number, status };
            } else {
                let newId = packages.length > 0 ? Math.max(...packages.map(p => p.id)) + 1 : 1;
                packages.push({ id: newId, number, status });
            }
            localStorage.setItem('packages', JSON.stringify(packages));
            renderPackages(packages);
            let packageModal = bootstrap.Modal.getInstance(document.getElementById('packageModal'));
            packageModal.hide();
        }

        function deletePackage(id) {
            let packages = JSON.parse(localStorage.getItem('packages'));
            packages = packages.filter(p => p.id!== id);
            localStorage.setItem('packages', JSON.stringify(packages));
            renderPackages(packages);
        }

        function searchPackages() {
            let searchTerm = document.getElementById('packageSearch').value.toLowerCase();
            let packages = JSON.parse(localStorage.getItem('packages'));
            let filteredPackages = packages.filter(package => package.number.toLowerCase().includes(searchTerm));
            renderPackages(filteredPackages);
        }

        // 订单管理
        function initOrders() {
            let orders = JSON.parse(localStorage.getItem('orders')) || [
                { id: 1, number: 'ORDER0001', time: '2024-01-01 10:00' },
                { id: 2, number: 'ORDER0002', time: '2024-01-02 11:00' },
                { id: 3, number: 'ORDER0003', time: '2024-01-03 12:00' },
                { id: 4, number: 'ORDER0004', time: '2024-01-04 13:00' },
                { id: 5, number: 'ORDER0005', time: '2024-01-05 14:00' },
                { id: 6, number: 'ORDER0006', time: '2024-01-06 15:00' },
                { id: 7, number: 'ORDER0007', time: '2024-01-07 16:00' },
                { id: 8, number: 'ORDER0008', time: '2024-01-08 17:00' },
                { id: 9, number: 'ORDER0009', time: '2024-01-09 18:00' },
                { id: 10, number: 'ORDER0010', time: '2024-01-10 19:00' }
            ];
            localStorage.setItem('orders', JSON.stringify(orders));
            renderOrders(orders);
        }

        function renderOrders(orders) {
            let orderTable = document.getElementById('orderTable').getElementsByTagName('tbody')[0];
            orderTable.innerHTML = '';
            orders.forEach(order => {
                let row = orderTable.insertRow();
                row.insertCell(0).textContent = order.id;
                row.insertCell(1).textContent = order.number;
                row.insertCell(2).textContent = order.time;
                let actionsCell = row.insertCell(3);
                actionsCell.innerHTML = `<button class="btn btn-warning" onclick="openEditOrderModal(${order.id})">编辑</button>
                                         <button class="btn btn-danger" onclick="deleteOrder(${order.id})">删除</button>`;
            });
        }

        function openAddOrderModal() {
            document.getElementById('orderId').value = '';
            document.getElementById('orderNumber').value = '';
            document.getElementById('orderTime').value = '';
            let orderModal = new bootstrap.Modal(document.getElementById('orderModal'));
            orderModal.show();
        }

        function openEditOrderModal(id) {
            let orders = JSON.parse(localStorage.getItem('orders'));
            let order = orders.find(o => o.id === id);
            document.getElementById('orderId').value = order.id;
            document.getElementById('orderNumber').value = order.number;
            document.getElementById('orderTime').value = order.time;
            let orderModal = new bootstrap.Modal(document.getElementById('orderModal'));
            orderModal.show();
        }

        function saveOrder() {
            let orders = JSON.parse(localStorage.getItem('orders'));
            let id = document.getElementById('orderId').value;
            let number = document.getElementById('orderNumber').value;
            let time = document.getElementById('orderTime').value;
            if (id) {
                let index = orders.findIndex(o => o.id === parseInt(id));
                orders[index] = { id: parseInt(id), number, time };
            } else {
                let newId = orders.length > 0 ? Math.max(...orders.map(o => o.id)) + 1 : 1;
                orders.push({ id: newId, number, time });
            }
            localStorage.setItem('orders', JSON.stringify(orders));
            renderOrders(orders);
            let orderModal = bootstrap.Modal.getInstance(document.getElementById('orderModal'));
            orderModal.hide();
        }

        function deleteOrder(id) {
            let orders = JSON.parse(localStorage.getItem('orders'));
            orders = orders.filter(o => o.id!== id);
            localStorage.setItem('orders', JSON.stringify(orders));
            renderOrders(orders);
        }

        function searchOrders() {
            let searchTerm = document.getElementById('orderSearch').value.toLowerCase();
            let orders = JSON.parse(localStorage.getItem('orders'));
            let filteredOrders = orders.filter(order => order.number.toLowerCase().includes(searchTerm));
            renderOrders(filteredOrders);
        }

        // 反馈管理
        function initFeedbacks() {
            let feedbacks = JSON.parse(localStorage.getItem('feedbacks')) || [
                { id: 1, person: '反馈人1', content: '反馈内容1' },
                { id: 2, person: '反馈人2', content: '反馈内容2' },
                { id: 3, person: '反馈人3', content: '反馈内容3' },
                { id: 4, person: '反馈人4', content: '反馈内容4' },
                { id: 5, person: '反馈人5', content: '反馈内容5' },
                { id: 6, person: '反馈人6', content: '反馈内容6' },
                { id: 7, person: '反馈人7', content: '反馈内容7' },
                { id: 8, person: '反馈人8', content: '反馈内容8' },
                { id: 9, person: '反馈人9', content: '反馈内容9' },
                { id: 10, person: '反馈人10', content: '反馈内容10' }
            ];
            localStorage.setItem('feedbacks', JSON.stringify(feedbacks));
            renderFeedbacks(feedbacks);
        }

        function renderFeedbacks(feedbacks) {
            let feedbackTable = document.getElementById('feedbackTable').getElementsByTagName('tbody')[0];
            feedbackTable.innerHTML = '';
            feedbacks.forEach(feedback => {
                let row = feedbackTable.insertRow();
                row.insertCell(0).textContent = feedback.id;
                row.insertCell(1).textContent = feedback.person;
                row.insertCell(2).textContent = feedback.content;
                let actionsCell = row.insertCell(3);
                actionsCell.innerHTML = `<button class="btn btn-warning" onclick="openEditFeedbackModal(${feedback.id})">编辑</button>
                                         <button class="btn btn-danger" onclick="deleteFeedback(${feedback.id})">删除</button>`;
            });
        }

        function openAddFeedbackModal() {
            document.getElementById('feedbackId').value = '';
            document.getElementById('feedbackPerson').value = '';
            document.getElementById('feedbackContent').value = '';
            let feedbackModal = new bootstrap.Modal(document.getElementById('feedbackModal'));
            feedbackModal.show();
        }

        function openEditFeedbackModal(id) {
            let feedbacks = JSON.parse(localStorage.getItem('feedbacks'));
            let feedback = feedbacks.find(f => f.id === id);
            document.getElementById('feedbackId').value = feedback.id;
            document.getElementById('feedbackPerson').value = feedback.person;
            document.getElementById('feedbackContent').value = feedback.content;
            let feedbackModal = new bootstrap.Modal(document.getElementById('feedbackModal'));
            feedbackModal.show();
        }

        function saveFeedback() {
            let feedbacks = JSON.parse(localStorage.getItem('feedbacks'));
            let id = document.getElementById('feedbackId').value;
            let person = document.getElementById('feedbackPerson').value;
            let content = document.getElementById('feedbackContent').value;
            if (id) {
                let index = feedbacks.findIndex(f => f.id === parseInt(id));
                feedbacks[index] = { id: parseInt(id), person, content };
            } else {
                let newId = feedbacks.length > 0 ? Math.max(...feedbacks.map(f => f.id)) + 1 : 1;
                feedbacks.push({ id: newId, person, content });
            }
            localStorage.setItem('feedbacks', JSON.stringify(feedbacks));
            renderFeedbacks(feedbacks);
            let feedbackModal = bootstrap.Modal.getInstance(document.getElementById('feedbackModal'));
            feedbackModal.hide();
        }

        function deleteFeedback(id) {
            let feedbacks = JSON.parse(localStorage.getItem('feedbacks'));
            feedbacks = feedbacks.filter(f => f.id!== id);
            localStorage.setItem('feedbacks', JSON.stringify(feedbacks));
            renderFeedbacks(feedbacks);
        }

        function searchFeedbacks() {
            let searchTerm = document.getElementById('feedbackSearch').value.toLowerCase();
            let feedbacks = JSON.parse(localStorage.getItem('feedbacks'));
            let filteredFeedbacks = feedbacks.filter(feedback => feedback.person.toLowerCase().includes(searchTerm));
            renderFeedbacks(filteredFeedbacks);
        }

        // 初始化图表
        function initChart() {
            // 初始化饼图
            let ctxPie = document.getElementById('myPieChart').getContext('2d');
            let couriers = JSON.parse(localStorage.getItem('couriers')).length;
            let students = JSON.parse(localStorage.getItem('students')).length;
            let packages = JSON.parse(localStorage.getItem('packages')).length;
            let orders = JSON.parse(localStorage.getItem('orders')).length;
            let feedbacks = JSON.parse(localStorage.getItem('feedbacks')).length;
            new Chart(ctxPie, {
                type: 'pie',
                data: {
                    labels: ['快递员数量', '学生数量', '包裹数量', '订单数量', '反馈数量'],
                    datasets: [{
                        label: '数据统计',
                        data: [couriers, students, packages, orders, feedbacks],
                        backgroundColor: [
                            'rgba(255, 99, 132, 0.2)',
                            'rgba(54, 162, 235, 0.2)',
                            'rgba(255, 205, 86, 0.2)',
                            'rgba(75, 192, 192, 0.2)',
                            'rgba(153, 102, 255, 0.2)'
                        ],
                        borderColor: [
                            'rgba(255, 99, 132, 1)',
                            'rgba(54, 162, 235, 1)',
                            'rgba(255, 205, 86, 1)',
                            'rgba(75, 192, 192, 1)',
                            'rgba(153, 102, 255, 1)'
                        ],
                        borderWidth: 1
                    }]
                },
                options: {}
            });
        }

        // 页面加载完成后初始化
        window.onload = function () {
            init();
        };
    </script>
</body>

</html>